package com.qq.crawiling_weather.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.qq.crawiling_weather.Util.JsonChange;
import com.qq.crawiling_weather.entity.Cityweather;
import com.qq.crawiling_weather.service.impl.CityweatherServiceImpl;
import com.sun.org.apache.xpath.internal.objects.XNull;
import org.apache.logging.log4j.core.util.JsonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 杨清林
 * @since 2021-01-09
 */
@Controller
@RequestMapping("/crawiling_weather/cityweather")
public class CityweatherController {

    @Autowired
    CityweatherServiceImpl cityweatherService;


    @RequestMapping("/test")
    @ResponseBody
    public Map<String, Object> test(@RequestParam(required=false,defaultValue="1") int page,
        @RequestParam(required=false) int limit) {


        List<Cityweather> cityweathers = cityweatherService.queryAllCityWeather();
//        Map<String, Object> map = JsonChange.change(cityweathers);


        IPage<Cityweather> CityWeatherPage = new Page<>(page, limit);//参数一是当前页，参数二是每页个数
        CityWeatherPage = cityweatherService.selectPage(CityWeatherPage);
        List<Cityweather> list = CityWeatherPage.getRecords();

        Map<String, Object> map = JsonChange.change(list,cityweathers.size());
//        System.out.println(map);

        return map;


    }


    @RequestMapping("/index")
    public String index() {


        return "index";
    }


    @RequestMapping("/login")
    public String login() {


        return "login";
    }

}
